#include "pair.h"

#include <utility>

/*
 * Constructors & destructor
 */

Pair::Pair() : left(0), right(0) {}

Pair::Pair(int left, int right) : left(left), right(right) {}

Pair::Pair(const Pair &other) {
    this->left = other.left;
    this->right = other.right;
}

Pair::~Pair() {}

/*
 * Setters & getters
 */

void Pair::setLeft(int v) {
    this->left = v;
}

void Pair::setRight(int v) {
    this->right = v;
}

int Pair::getLeft() const {
    return this->left;
}

int Pair::getRight() const {
    return this->right;
}

/*
 * Overloads
 */

Pair & Pair::operator=(const Pair &other) {
    if(this == &other) return *this;

    this->left = other.left;
    this->right = other.right;
    return *this;
}

Pair & Pair::operator=(Pair &&other) noexcept {
    if(this == &other) return *this;

    this->left = std::exchange(other.left, 0);
    this->right = std::exchange(other.right, 0);
    return *this;
}

std::ostream & operator<<(std::ostream &os, const Pair &pair) {
    os << "< " << pair.left << ", " << pair.right << " >";
    return os;
}

std::istream & operator>>(std::istream &is, Pair &pair) {
    is >> pair.left >> pair.right;
    return is;
}

/*
 * Public methods (interface)
 */

int Pair::mul() const {
    return this->left * this->right;
}
